home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / unix4pc.arc / UNIX4PC.NET
Encoding:
Text File  |  1985-09-04  |  48.7 KB  |  2,129 lines

  1.  
  2.  
  3. Here are some unix style tools that also run on IBM PC.
  4. Cut it and pass it through sh.
  5. Read readme.ut1 first.
  6. Here is a list of the programs in this posting:
  7. expand, dost2b, dosb2t, hxd, which, crc16, sarch.
  8.  
  9. ----------------------- CUT HERE ----------------------
  10. # The rest of this file is a shell script which will extract:
  11. # readme.ut1 mkp makefile pcust1.bat mbstd.h msc3.h crc16.c dosb2t.c dost2b.c expand.c fcrc16.c hxd.c sarch.c which.c
  12. echo x - readme.ut1
  13. cat >readme.ut1 <<'!Funky!Stuff!'
  14. Here are a few simple tools that run identically or very similarly
  15. under msdos and unix. 
  16.  
  17. I am calling them ust1, Unix Style Tools. Couldn't come up with 
  18. a better name.
  19.  
  20. They have only minimally been tested under msdos and bsd4.2.
  21. MSC 3.0 was used under msdos.
  22. I did make an effort to make the code portable. They probably would 
  23. run under a few other systems.
  24.  
  25. Mail bug reports and problems to me. I'll re-post.
  26.  
  27. expand:
  28.  *  Expand mimics Unix's expand. It is not a full implementation.
  29.  *  Does not support [-tab1,tab2,..,tabn].
  30.  *  Expand is a filter.
  31.  *  It processes the named files or the standard input.
  32.  *  It writes to standard output with tabs changed into blanks.
  33.  *  
  34.  * Usages:
  35.  *  expand [-tabstop] [i_files]
  36.     Back space can easily be added to it.
  37.  
  38. dost2b:
  39.  *  dost2b is a filter.
  40.  *  dost2b processes i_files or the standard input.
  41.  *  dost2b writes to o_file or standard output.
  42.  *  Converts a DOS text file to binary file.
  43.  *  Replaces <cr><lf> to <lf>.
  44.  *
  45.  * Usages:
  46.  *  dost2b [-o] <o_file> <i_files>
  47.  
  48. dosb2t:
  49.  *  dosb2t is a filter.
  50.  *  dosb2t processes i_files or the standard input.
  51.  *  dosb2t writes to o_file or standard output.
  52.  *  Converts a DOS binary file to text file.
  53.  *  Replaces <lf> with <cr><lf>.
  54.  *  
  55.  * Usages:
  56.  *  dosb2t [-o] <o_file> <i_files>
  57.  
  58. hxd:
  59.  *  hxd, Hexadecimal dump is similar unix's "od -x"
  60.  *  Displays the contents of a file in hexadecimal.
  61.  *  If a byte is printable, it is also printed.
  62.  *  For each in put file name of the file is first emited.
  63.  *      file: <i_file>
  64.  *  last line for each input file is length of the file in 
  65.  *      "dec_add:hex_add" format.
  66.  *
  67.  * Usages:
  68.  *  hxd [-o] <o_file> <i_files>
  69.     See Comments in hxd.c.
  70.  
  71. which:
  72.  *  Tries to mimic Unix's which as closely as possible.
  73.  *  
  74.  * Usages:
  75.  *  which <i_files>
  76.     This is basically Larry Barello's which. 
  77.     For DOS .{com,exe,bat} are tested for existance.
  78.     Only the first one that exists is printed.
  79.     Internal DOS programs could later be added.
  80.  
  81. crc16:
  82.     This is basically Hugh Redelmeir's version.
  83.     I needed to modify it so that it could also be
  84.     used by sarch.
  85.  
  86. sarch:
  87.  *      This is a simple archive utility program.
  88.  *      Sarch tries to only rely on the C stdio library functions.
  89.  *      When transferring multiple files between two machines that only have a
  90.  *      single file transfer utility, sarch becomes handy. Multiple files
  91.  *      are converted to a sinle file on one end, transfered to the other 
  92.  *      machine and extracted to the original files at the destination.
  93.  *      System dependent features are very few, keeping it simple
  94.  *      and portable. Efficiency is sacrificed for portability.
  95.  *      CRCs are computed when updateing and when extracting.
  96.  *  
  97.  * Usage:
  98.  *  sarch -{m,u,x,a,t} archname file1 .. filen
  99.  *      -m      Print file names within the archive.
  100.  *      -u      Add or update files to the archive.
  101.  *      -x      Extract files from archive.
  102.  *      -a      Extract all files from the rachive.
  103.  *      -t      PCDOS related. When extracting, test mode is set.
  104.     Sarch is NOT COMPLETE. 
  105.     I am posting it because it can be useful if used carefully.
  106.     No flames on this one, please.
  107.     I am also not happy with th command syntax.
  108.     Only -u and -a work. As is, it is only useful for moving files
  109.     around. 
  110.     sarch -u ar file1 filen   , on one end.
  111.     sarch -a ar , on the other end.
  112.  
  113.  
  114. FILES:
  115.     mkp:
  116.         Is a Csh script that runs make.
  117.         It can be useful when you are supporting native and cross
  118.         development. Some don't like it. I do.
  119.     makefile:
  120.         File dependencies only. Needs mkp.
  121.     pcust1.bat:
  122.         run this on the pc to create everything.
  123.     mbstd.h:
  124.         Standard Header I use.
  125.     expand.c dost2b.c dosb2t.c hxd.c sarch.c which.c fcrc16.c crc16.c:
  126.         C source files.
  127.     readme.ut1:
  128.         This file.
  129.     
  130. TO RUN:
  131.     bsd4.2
  132.         first make mkp executable.
  133.         mkp 
  134.     msdos, msc
  135.         make sure that all headers and libraries are there.
  136.         make sure ssetargv.obj is in current directory.
  137.         run pcust1.bat
  138. !Funky!Stuff!
  139. echo x - mkp
  140. cat >mkp <<'!Funky!Stuff!'
  141. #!/bin/csh -f
  142. # This is the make pre-processor program written in the 'C' shell.
  143. #
  144. #   mkp defines a group of parameters and passes them to make.
  145. #   SWITCHES:
  146. #       -f <filename>
  147. #           source <filename. priore to invoking make.
  148. #           If -f is not present and .mkprc exists in the current directory
  149. #           it is sourced. Otherwise if .mkprc exists in the home directory
  150. #           it is sourced.
  151. #       -- 
  152. #           argument parsing is terminated remainder of command line is passed
  153. #           to make as is.
  154. #
  155. set MKPFILE=.mkprc
  156. set mkpname=$0
  157. set mkpname=$mkpname:t
  158. # ### VISIBLE MAKE TOOLS
  159. set MAKE=make
  160. set CC=cc
  161. set AS="as -"
  162. set LK=""
  163. set LD=""
  164. set LINT="lint -u"
  165. set REMOVE="rm -f"
  166. set CTAGS="ctags -w"
  167. # Internal parametrs
  168. set INCFLAGS = -I.
  169. # ### VISIBLE MAKE PARAMETERS
  170. #set CFLAGS = "${INCFLAGS} -DBSD4_2 -Uunix -DMSDOS"
  171. set CFLAGS = "${INCFLAGS} -DBSD4_2 "
  172. set LINTFLAGS = ${INCFLAGS}
  173. set TARGETS
  174. # MKP FLAGS
  175. set S_MKPFILE
  176. umask 002
  177. #^L
  178. #
  179. # Gather command line options
  180. #
  181. foreach i ($*)
  182.     switch ($1)
  183.     case -f:
  184.         shift argv
  185.         set S_MKPFILE=$1
  186.         breaksw
  187.     case --:
  188.         shift argv
  189.         break
  190.     default:
  191.         break
  192.         breaksw
  193.     endsw
  194.     shift argv
  195. end
  196. #
  197. #
  198. #
  199. #
  200. if ("$S_MKPFILE" != "") then
  201.     set MKPFILE = "$S_MKPFILE"
  202.     source $MKPFILE
  203. else if (-f $MKPFILE) then
  204.     source $MKPFILE
  205. else if (-f $HOME/$MKPFILE) then
  206.     source $HOME/$MKPFILE
  207. endif
  208. #
  209. set TARGETS="$*"
  210. #
  211. $MAKE  "CC=$CC" "AS=$AS" \
  212.     "CFLAGS=$CFLAGS" "LINTFLAGS=$LINTFLAGS" \
  213.     "LINT=$LINT"  \
  214.     "REMOVE=$REMOVE" "CTAGS=$CTAGS" \
  215.     $TARGETS
  216. set ret=$status
  217. if ("$ret" != "0") then
  218.     exit 1
  219. endif
  220. exit 0
  221. !Funky!Stuff!
  222. echo x - makefile
  223. cat >makefile <<'!Funky!Stuff!'
  224. # ::::::::::::::::::::::::::::::::::::::::::::::::::
  225. #
  226. #  File: Makefile
  227. #  Description: Makefile for creating  UST1
  228. #
  229. #
  230. #  Audit Trail:  $Log:  makefile,v $
  231. # Revision 1.1  85/08/28  08:38:38  mohsen
  232. # original posting to the net
  233. #
  234. #  $Header: makefile,v 1.1 85/08/28 08:38:38 mohsen Exp $
  235. #
  236. # ::::::::::::::::::::::::::::::::::::::::::::::::::
  237.  
  238. MAKEFILE = makefile
  239. TARGET = ust1
  240. PUB_H = mbstd.h msc3.h
  241. LCL_H =
  242. LCL_C = expand.c dost2b.c dosb2t.c hxd.c sarch.c which.c fcrc16.c \
  243.                 crc16.c 
  244. C_SRC =  ${PUB_H} ${LCL_H} ${LCL_C}
  245.  
  246. ${TARGET}: expand dost2b dosb2t hxd crc16 which sarch
  247. #
  248. expand:   expand.o
  249.                 cc -o expand expand.o
  250. #
  251. dost2b:  dost2b.o
  252.                 cc -o dost2b dost2b.o
  253. #
  254. dosb2t:  dosb2t.o
  255.                 cc -o dosb2t dosb2t.o
  256. #
  257. hxd:     hxd.o
  258.                 cc -o hxd hxd.o
  259. #
  260. crc16:   crc16.o fcrc16.o
  261.                 cc -o crc16 crc16.o fcrc16.o
  262. #
  263. sarch:   sarch.o
  264.                 cc -o sarch sarch.o fcrc16.o
  265. #
  266. which:   which.o
  267.                 cc -o which which.o
  268. #
  269. e_make:
  270.         @echo ${MAKEFILE}
  271. e_pub_h:
  272.         @echo ${PUB_H}
  273. e_lcl_h:
  274.         @echo ${LCL_H}
  275. e_lcl_c:
  276.         @echo ${LCL_C}
  277. e_c_src:
  278.         @echo ${C_SRC}
  279. #
  280. ctags:  ${LCL_C}
  281.                 $(CTAGS) $(LCL_C)
  282. #
  283. lint:
  284.                 $(LINT) $(LCL_C)
  285.  
  286. !Funky!Stuff!
  287. echo x - pcust1.bat
  288. cat >pcust1.bat <<'!Funky!Stuff!'
  289. cl -c -DMSDOS expand.c
  290. cl -o expand expand.obj ssetargv.obj
  291. cl -c -DMSDOS dost2b.c
  292. cl -o dost2b dost2b.obj ssetargv.obj
  293. cl -c -DMSDOS dosb2t.c
  294. cl -o dosb2t dosb2t.obj ssetargv.obj
  295. cl -c -DMSDOS hxd.c
  296. cl -o hxd hxd.obj ssetargv.obj
  297. cl -c -DMSDOS fcrc16.c
  298. cl -c -DMSDOS crc16.c
  299. cl -o crc16 crc16.obj fcrc16.obj ssetargv.obj
  300. cl -c -DMSDOS sarch.c
  301. cl -o sarch sarch.obj fcrc16.obj ssetargv.obj
  302. cl -c -DMSDOS which.c
  303. cl -o which which.obj ssetargv.obj
  304. !Funky!Stuff!
  305. echo x - mbstd.h
  306. cat >mbstd.h <<'!Funky!Stuff!'
  307. #ifndef MBSTD_H
  308. #define MBSTD_H
  309.  
  310. #define CHAR    char
  311. #define SCHAR   char
  312. typedef unsigned char  UCHAR;
  313.  
  314. #define INT     int
  315. #define SINT    int
  316. typedef unsigned int UINT;
  317.  
  318. #define SHORT   short
  319. #define SSHORT  short
  320. typedef unsigned short USHORT;
  321.  
  322. #define LONG    long
  323. #define SLONG   long
  324. typedef unsigned long ULONG;
  325.  
  326. #define DOUBLE  double
  327.  
  328. #define BOOL    int
  329. #define SUCC_FAIL   int 
  330. #ifndef VOID
  331. #define VOID    void
  332. #endif
  333.  
  334. #define STATIC  static      /* Names not needed outside this src module  */
  335.  
  336. #define LOCAL               /* Names not needed outside this software module */
  337. #define LCL_XTRN extern     /* Names defined within this software module */
  338.  
  339. #define PUBLIC              /* Names needed outside this software module */
  340. #define EXTERN  extern      /* Names defined outside this software module */
  341.  
  342. #define TRUE    1
  343. #define FALSE   0
  344.  
  345. #define SUCCESS 0
  346. #define FAIL    (-1)
  347.  
  348. #endif MBSTD_H
  349. !Funky!Stuff!
  350. echo x - msc3.h
  351. cat >msc3.h <<'!Funky!Stuff!'
  352. #ifndef MSC3_H
  353. #define MSC3_H
  354.  
  355. #ifdef unix
  356. #define O_TEXT   0x4000
  357. #define O_BINARY 0x8000
  358. setmode(handle, mode)
  359. int handle;
  360. int mode;
  361. {}
  362. #endif
  363.  
  364. #endif MSC3_H
  365. !Funky!Stuff!
  366. echo x - crc16.c
  367. cat >crc16.c <<'!Funky!Stuff!'
  368. /*+
  369.  * File: crc16.c
  370.  * Description:
  371.  *  Computes crc for the named filenames.
  372.  *  Output has this formatt.
  373.  *      file=[i_file], size=[fsize], crc=[decval](dec)=[hexval](hex)
  374.  *  
  375.  * Usages:
  376.  *  crc16 <i_files>
  377.  *
  378.  *  Author: Mohsen Banan.
  379.  *
  380.  *  This program is public domain software, no warranty intended or
  381.  *  implied.
  382.  *  General permission to copy or modify, but not for profit,  is
  383.  *  hereby  granted.
  384.  *
  385.  * Functions:
  386.  *
  387.  *
  388.  * Audit Trail:  $Log:  crc16.c,v $
  389.  * Revision 1.1  85/08/28  08:38:12  mohsen
  390.  * original posting to the net
  391.  * 
  392.  * 
  393.  *
  394. -*/
  395.  
  396. #ifdef RCS_VER
  397. static char *rcs = "$Header: crc16.c,v 1.1 85/08/28 08:38:12 mohsen Exp $";
  398. #endif
  399.  
  400. /* #includes */
  401. #include "mbstd.h"
  402. #include <stdio.h>
  403. #include <ctype.h>
  404. #include <fcntl.h>
  405. #ifdef unix
  406. #include "msc3.h"
  407. #endif
  408.  
  409. /* #defines */
  410.  
  411. /* external variables */
  412.  
  413. /* referenced external function declarations */
  414. EXTERN USHORT fcrc16();
  415. /* internal function declarations */
  416. PUBLIC VOID crc16();
  417. PUBLIC VOID cant_open();
  418. STATIC VOID usage();
  419.  
  420. /* global variables */
  421.  
  422. /* static variables */
  423. STATIC CHAR * prog_name;
  424.  
  425.  
  426. INT
  427. main (argc, argv)
  428. INT argc;
  429. CHAR * argv[];
  430. {
  431.     crc16(argc, argv);
  432. }
  433.     
  434. ^L
  435. --MORE--(22%)
  436. /*<
  437.  * Function:crc16
  438.  * Description:
  439.  *
  440.  * Returns:
  441.  *  VOID
  442.  *  
  443. >*/
  444. PUBLIC VOID 
  445. crc16 (argc,argv)
  446. INT argc;
  447. CHAR * argv[];
  448. {
  449.     FILE * i_fp;
  450.     FILE * o_fp;
  451.  
  452.     INT i;
  453.     USHORT crc;
  454.     LONG fsize ;
  455.  
  456.     i_fp = stdin;
  457.     o_fp = stdout;
  458.     prog_name = argv[0];
  459.     for (i=1; i<argc; ++i) {
  460.         if (*argv[i] == '-') {
  461.             /* To handle concatenated switches */
  462.             INT j;
  463.             j=i;
  464.             while (*(++argv[j])) {
  465.                 switch (*argv[j]) {
  466.                 case 'o':
  467.                 case 'O':
  468.                     if ( !(o_fp = fopen(argv[++i], "w")) ) {
  469.                         cant_open (prog_name, argv[i]);
  470.                         exit (1);
  471.                     }
  472.                     break;
  473.                 default:
  474.                     usage();
  475.                     exit(1);
  476.                 } /* switch (*argv[j]) */
  477.             } /* while (*(++argv[j])) */
  478.         } /* if '-' */
  479.         else {
  480.             if (!(i_fp = fopen (argv[i], "r"))) {
  481.                 cant_open (prog_name, argv[i]);
  482.                 exit (1);
  483.             } 
  484.             setmode (fileno(i_fp), O_BINARY);
  485.             setmode (fileno(o_fp), O_TEXT);
  486.             crc = fcrc16 (i_fp, 0, &fsize);
  487.             fprintf (o_fp, "file=%s, size=%ld, crc=%u(dec)=%x(hex)\n",
  488.                     argv[i], fsize, crc, crc);
  489.             fclose (i_fp);
  490.         }
  491.     } /* for i<argc */
  492.     fclose (o_fp);
  493.     exit (0);
  494. }
  495.  
  496. PUBLIC VOID
  497. cant_open (prog_name,filename)
  498. CHAR * prog_name;
  499. CHAR * filename;
  500. {
  501.     fprintf (stderr, "%s :can not open %s \n", prog_name, filename);
  502.  
  503. STATIC VOID
  504. usage ()
  505. {
  506.     fprintf (stderr, "Usage: %s <i_files> \n", prog_name);
  507. }
  508.  
  509.  
  510.  
  511. !Funky!Stuff!
  512. echo x - dosb2t.c
  513. cat >dosb2t.c <<'!Funky!Stuff!'
  514.  
  515. /*+
  516.  * File: dosb2t.c
  517.  * Description:
  518.  *  dosb2t is a filter.
  519.  *  dosb2t processes i_files or the standard input.
  520.  *  dosb2t writes to o_file or standard output.
  521.  *
  522.  *  Converts a DOS binary file to text file.
  523.  *  Replaces <lf> with <cr><lf>.
  524.  *  
  525.  * Usages:
  526.  *  dosb2t [-o] <o_file> <i_files>
  527.  *
  528.  *
  529.  *  Author: Mohsen Banan.
  530.  *
  531.  *  This program is public domain software, no warranty intended or
  532.  *  implied.
  533.  *  General permission to copy or modify, but not for profit,  is
  534.  *  hereby  granted.
  535.  *
  536.  *
  537.  * Functions:
  538.  *
  539.  *
  540.  * Audit Trail:  $Log:  dosb2t.c,v $
  541.  * Revision 1.1  85/08/28  08:38:24  mohsen
  542.  * original posting to the net
  543.  * 
  544.  * 
  545.  *
  546. -*/
  547.  
  548. #ifdef RCS_VER
  549. static char *rcs = "$Header: dosb2t.c,v 1.1 85/08/28 08:38:24 mohsen Exp $";
  550. #endif
  551.  
  552. /* #includes */
  553. #include "mbstd.h"
  554. #include <stdio.h>
  555. #include <ctype.h>
  556. #include <fcntl.h>
  557. #ifdef unix
  558. #include "msc3.h"
  559. #endif
  560.  
  561. /* #defines */
  562.  
  563. /* external variables */
  564.  
  565. /* referenced external function declarations */
  566.  
  567. /* internal function declarations */
  568. PUBLIC VOID dosb2t();
  569. PUBLIC VOID cant_open();
  570. STATIC VOID usage();
  571.  
  572. /* global variables */
  573.  
  574. /* static variables */
  575. STATIC CHAR * prog_name;
  576.  
  577.  
  578. INT
  579. main (argc, argv)
  580. INT argc;
  581. CHAR * argv[];
  582. {
  583.     dosb2t(argc, argv);
  584. }
  585.     
  586. ^L
  587. --MORE--(29%)
  588. /*<
  589.  * Function:dosb2t
  590.  * Description:
  591.  *
  592.  * Returns:
  593.  *  VOID
  594.  *  
  595. >*/
  596. PUBLIC VOID 
  597. dosb2t (argc,argv)
  598. INT argc;
  599. CHAR * argv[];
  600. {
  601.     FILE * i_fp;
  602.     FILE * o_fp;
  603.  
  604.     INT i;
  605.     INT c;
  606.  
  607.     i_fp = stdin;
  608.     o_fp = stdout;
  609.     prog_name = argv[0];
  610.     for (i=1; i<argc; ++i) {
  611.         if (*argv[i] == '-') {
  612.             /* To handle concatenated switches */
  613.             INT j;
  614.             j=i;
  615.             while (*(++argv[j])) {
  616.                 switch (*argv[j]) {
  617.                 case 'o':
  618.                 case 'O':
  619.                     if ( !(o_fp = fopen(argv[++i], "w")) ) {
  620.                         cant_open (prog_name, argv[i]);
  621.                         exit (1);
  622.                     }
  623.                     break;
  624.                 default:
  625.                     usage();
  626.                     exit(1);
  627.                 } /* switch (*argv[j]) */
  628.             } /* while (*(++argv[j])) */
  629.         } /* if '-' */
  630.         else {
  631.             if (!(i_fp = fopen (argv[i], "r"))) {
  632.                 cant_open (prog_name, argv[i]);
  633.                 exit (1);
  634.             } 
  635.             setmode (fileno(i_fp), O_BINARY);
  636.             setmode (fileno(o_fp), O_TEXT);
  637.             while (( c = getc (i_fp)) != EOF) {
  638.                 putc (c, o_fp);
  639.             }
  640.             fclose (i_fp);
  641.         }
  642.     } /* for i<argc */
  643.     fclose (o_fp);
  644.     exit (0);
  645. }
  646.  
  647. PUBLIC VOID
  648. cant_open (prog_name,filename)
  649. CHAR * prog_name;
  650. CHAR * filename;
  651. {
  652.     fprintf (stderr, "%s :can not open %s \n", prog_name, filename);
  653.  
  654. STATIC VOID
  655. usage ()
  656. {
  657.     fprintf (stderr, "Usage: %s [-o] <o_file> <i_files> \n", prog_name);
  658. }
  659.  
  660.  
  661. !Funky!Stuff!
  662. echo x - dost2b.c
  663. cat >dost2b.c <<'!Funky!Stuff!'
  664. /*+
  665.  * File: dost2b.c
  666.  * Description:
  667.  *  dost2b is a filter.
  668.  *  dost2b processes i_files or the standard input.
  669.  *  dost2b writes to o_file or standard output.
  670.  *
  671.  *  Converts a DOS text file to binary file.
  672.  *  Replaces <cr><lf> to <lf>.
  673.  *
  674.  * Usages:
  675.  *  dost2b [-o] <o_file> <i_files>
  676.  * 
  677.  *
  678.  *  Author: Mohsen Banan.
  679.  *
  680.  *  This program is public domain software, no warranty intended or
  681.  *  implied.
  682.  *  General permission to copy or modify, but not for profit,  is
  683.  *  hereby  granted.
  684.  *
  685.  *
  686.  * Functions:
  687.  *
  688.  *
  689.  * Audit Trail:  $Log:  dost2b.c,v $
  690.  * Revision 1.1  85/08/28  08:38:28  mohsen
  691.  * original posting to the net
  692.  * 
  693.  * 
  694.  *
  695. -*/
  696.  
  697. #ifdef RCS_VER
  698. static char *rcs = "$Header: dost2b.c,v 1.1 85/08/28 08:38:28 mohsen Exp $";
  699. #endif
  700.  
  701. /* #includes */
  702. #include "mbstd.h"
  703. #include <stdio.h>
  704. #include <ctype.h>
  705. #include <fcntl.h>
  706. #ifdef unix
  707. #include "msc3.h"
  708. #endif
  709.  
  710. /* #defines */
  711.  
  712. /* external variables */
  713.  
  714. /* referenced external function declarations */
  715.  
  716. /* internal function declarations */
  717. PUBLIC VOID dost2b();
  718. PUBLIC VOID cant_open();
  719. STATIC VOID usage();
  720.  
  721. /* global variables */
  722.  
  723. /* static variables */
  724. STATIC CHAR * prog_name;
  725.  
  726. INT
  727. main (argc, argv)
  728. INT argc;
  729. CHAR * argv[];
  730. {
  731.     dost2b(argc, argv);
  732. }
  733.     
  734. ^L
  735. --MORE--(35%)
  736. /*<
  737.  * Function:dost2b
  738.  * Description:
  739.  *
  740.  * Returns:
  741.  *  VOID
  742.  * 
  743. >*/
  744. PUBLIC VOID 
  745. dost2b (argc,argv)
  746. INT argc;
  747. CHAR * argv[];
  748. {
  749.     FILE * i_fp;
  750.     FILE * o_fp;
  751.  
  752.     INT i;
  753.     INT c;
  754.  
  755.     i_fp = stdin;
  756.     o_fp = stdout;
  757.     prog_name = argv[0];
  758.     for (i=1; i<argc; ++i) {
  759.         if (*argv[i] == '-') {
  760.             /* To handle concatenated switches */
  761.             INT j;
  762.             j=i;
  763.             while (*(++argv[j])) {
  764.                 switch (*argv[j]) {
  765.                 case 'o':
  766.                 case 'O':
  767.                     if ( !(o_fp = fopen(argv[++i], "w")) ) {
  768.                         cant_open (prog_name, argv[i]);
  769.                         exit (1);
  770.                     }
  771.                     break;
  772.                 default:
  773.                     usage();
  774.                     exit(1);
  775.                 } /* switch (*argv[j]) */
  776.             } /* while (*(++argv[j])) */
  777.         } /* if '-' */
  778.         else {
  779.             if (!(i_fp = fopen (argv[i], "r"))) {
  780.                 cant_open (prog_name, argv[i]);
  781.                 exit (1);
  782.             } 
  783.             setmode (fileno(i_fp), O_TEXT);
  784.             setmode (fileno(o_fp), O_BINARY);
  785.             while (( c = getc (i_fp)) != EOF) {
  786.                 putc (c, o_fp);
  787.             }
  788.             fclose (i_fp);
  789.         }
  790.     } /* for i<argc */
  791.     fclose (o_fp);
  792.     exit (0);
  793. }
  794.  
  795. PUBLIC VOID
  796. cant_open (prog_name,filename)
  797. CHAR * prog_name;
  798. CHAR * filename;
  799. {
  800.     fprintf (stderr, "%s :can not open %s \n", prog_name, filename);
  801.  
  802. STATIC VOID
  803. usage ()
  804. {
  805.     fprintf (stderr, "Usage: %s [-o] <o_file> <i_files> \n", prog_name);
  806. }
  807.  
  808.  
  809. !Funky!Stuff!
  810. echo x - expand.c
  811. cat >expand.c <<'!Funky!Stuff!'
  812.  
  813. /*+
  814.  * File: expand.c
  815.  * Description:
  816.  *  Expand mimics Unix's expand. It is not a full implementation.
  817.  *  Does not support [-tab1,tab2,..,tabn].
  818.  *
  819.  *  Expand is a filter.
  820.  *  It processes the named files or the standard input.
  821.  *  It writes to standard output with tabs changed into blanks.
  822.  *  
  823.  * Usages:
  824.  *  expand [-tabstop] [i_files]
  825.  *
  826.  *
  827.  *  Author: Mohsen Banan.
  828.  *
  829.  *  This program is public domain software, no warranty intended or
  830.  *  implied.
  831.  *  General permission to copy or modify, but not for profit,  is
  832.  *  hereby  granted.
  833.  *
  834.  * Functions:
  835.  *
  836.  *
  837.  * Audit Trail:  $Log:  expand.c,v $
  838.  * Revision 1.1  85/08/28  08:38:31  mohsen
  839.  * original posting to the net
  840.  * 
  841.  * Revision 1.1  85/08/14  13:44:13  mohsen
  842.  * Initial revision
  843.  * 
  844.  * 
  845.  *
  846. -*/
  847.  
  848. #ifdef RCS_VER
  849. static char *rcs = "$Header: expand.c,v 1.1 85/08/28 08:38:31 mohsen Exp $";
  850. #endif
  851.  
  852. /* #includes */
  853. #include "mbstd.h"
  854. #include <stdio.h>
  855. #include <ctype.h>
  856. #include <fcntl.h>
  857. #ifdef unix
  858. #include "msc3.h"
  859. #endif
  860.  
  861. /* #defines */
  862.  
  863. /* external variables */
  864.  
  865. /* referenced external function declarations */
  866.  
  867. /* internal function declarations */
  868. PUBLIC VOID expand();
  869. PUBLIC VOID tab_putc();
  870. PUBLIC VOID cant_open();
  871. STATIC VOID usage();
  872.  
  873. /* global variables */
  874.  
  875. /* static variables */
  876. STATIC CHAR * prog_name;
  877. STATIC INT tabstop;
  878. STATIC INT cpos;
  879.  
  880. INT
  881. main (argc, argv)
  882. INT argc;
  883. CHAR * argv[];
  884. {
  885.     expand(argc, argv);
  886. }
  887.     
  888. ^L
  889. --MORE--(41%)
  890. /*<
  891.  * Function:expand
  892.  * Description:
  893.  *  Parses the command line and calls tab_putc.
  894.  *
  895.  * Returns:
  896.  *  VOID
  897.  * 
  898. >*/
  899. PUBLIC VOID 
  900. expand (argc,argv)
  901. INT argc;
  902. CHAR * argv[];
  903. {
  904.     FILE * i_fp;
  905.     FILE * o_fp;
  906.  
  907.     INT i;
  908.     INT c;
  909.  
  910.     i_fp = stdin;
  911.     o_fp = stdout;
  912.     tabstop = 8;
  913.     prog_name = argv[0];
  914.     for (i=1; i<argc; ++i) {
  915.         if (*argv[i] == '-') {
  916.             /* To handle concatenated switches */
  917.             INT j;
  918.             j=i;
  919.             while (*(++argv[j])) {
  920.                 if (isdigit(*(argv[j]))) {
  921.                     tabstop = atoi(argv[j]);
  922.                     break;
  923.                 }
  924. #if 0
  925.                 switch (*argv[j]) {
  926.                 case 'o':
  927.                 case 'O':
  928.                     if ( !(o_fp = fopen(argv[++i], "w")) ) {
  929.                         cant_open (prog_name, argv[i]);
  930.                         exit (1);
  931.                     }
  932.                     break;
  933.                 default:
  934.                     usage();
  935.                     exit(1);
  936.                 } /* switch (*argv[j]) */
  937. #endif
  938.             } /* while (*(++argv[j])) */
  939.         } /* if '-' */
  940.         else {
  941.             if (!(i_fp = fopen (argv[i], "r"))) {
  942.                 cant_open (prog_name, argv[i]);
  943.                 exit (1);
  944.             } 
  945.             setmode (fileno(i_fp), O_TEXT);
  946.             setmode (fileno(o_fp), O_TEXT);
  947.             cpos = 0;
  948.             while (( c = getc (i_fp)) != EOF) {
  949.                 tab_putc (c, o_fp);
  950.             }
  951.             fclose (i_fp);
  952.         }
  953.     } /* for i<argc */
  954.     fclose (o_fp);
  955.     exit (0);
  956. }
  957.  
  958. ^L
  959. --MORE--(44%)
  960. /*<
  961.  * Function:tab_putc
  962.  * Description:
  963.  *  Converts tabs to the correct number of spaces (tabstop).
  964.  *  tab_putc is recursive.
  965.  *
  966.  * Returns:
  967.  *  VOID
  968.  *
  969. >*/
  970. PUBLIC VOID
  971. tab_putc (c, o_fp)
  972. INT  c;
  973. FILE * o_fp;
  974. {
  975.     if (c == '\n') {
  976.         cpos = 0;
  977.         putc (c, o_fp);
  978.     } else if ( c== '\t') {
  979.         do {
  980.             tab_putc(' ', o_fp);
  981.         } while (cpos % tabstop);
  982.     }
  983.     else {
  984.         cpos++;
  985.         putc (c, o_fp);
  986.     }
  987. }
  988.  
  989. PUBLIC VOID
  990. cant_open (prog_name,filename)
  991. CHAR * prog_name;
  992. CHAR * filename;
  993. {
  994.     fprintf (stderr, "%s :can not open %s \n", prog_name, filename);
  995.  
  996. #if 0
  997. STATIC VOID
  998. usage ()
  999. {
  1000.     fprintf (stderr, "Usage: %s [-tabstop] [i_files]\n", prog_name);
  1001. }
  1002. #endif
  1003.  
  1004. !Funky!Stuff!
  1005. echo x - fcrc16.c
  1006. cat >fcrc16.c <<'!Funky!Stuff!'
  1007. /*+
  1008.  * File: fcrc16
  1009.  * Description:
  1010.  *      Calculates crc, given a file pointer.
  1011.  *
  1012.  *
  1013.  *  Author: Mohsen Banan.
  1014.  *
  1015.  *  This program is public domain software, no warranty intended or
  1016.  *  implied.
  1017.  *  General permission to copy or modify, but not for profit,  is
  1018.  *  hereby  granted.
  1019.  *
  1020.  *
  1021.  * Functions:
  1022.  *
  1023.  *
  1024.  * Audit Trail:  $Log:  fcrc16.c,v $
  1025.  * Revision 1.1  85/08/28  08:38:33  mohsen
  1026.  * original posting to the net
  1027.  * 
  1028.  * 
  1029.  *
  1030. -*/
  1031.  
  1032. #ifdef RCS_VER
  1033. static char *rcs = "$Header: fcrc16.c,v 1.1 85/08/28 08:38:33 mohsen Exp $";
  1034. #endif
  1035.  
  1036. /* #includes */
  1037. #include "mbstd.h"
  1038. #include <stdio.h>
  1039.  
  1040. /* #defines */
  1041.  
  1042. /* external variables */
  1043.  
  1044. /* referenced external function declarations */
  1045.  
  1046. /* internal function declarations */
  1047.  
  1048. /* global variables */
  1049.  
  1050. /* static variables */
  1051.  
  1052. ^L
  1053. --MORE--(48%)
  1054. /*<
  1055.  * Function:crc16_table
  1056.  * Description:
  1057.  *
  1058.  *  * Calculate CRC16 of a file.
  1059.  *  * CRC16 polynomial: x**0 + x**2 + x**15 + x**16 (0xA001)
  1060.  *  * (CCITT polynomial: x**0 + x**5 + x**12 + x**16 (0x8408))
  1061.  *  * 
  1062.  *  * D. Hugh Redelmeier  1983 April 15
  1063.  *
  1064.  *  Mohsen Banan: I don't know how CRCs work yet. 
  1065.  *  None of what is to follow is original work.
  1066.  *
  1067.  *
  1068.  * Returns:
  1069.  * 
  1070. >*/
  1071. #if 0
  1072. VOID 
  1073. crc16_table()
  1074. {
  1075.     register unsigned s, t;
  1076.     register int i;
  1077.  
  1078.     printf("unsigned short crctab[256] = {");
  1079.     for (t=0; ; ) {
  1080.         if (t%8 == 0)
  1081.             printf("\n");
  1082.         s = t;
  1083.         for (i=8; i--; )
  1084.             s = s>>1 ^ (s&1? 0xA001 : 0);
  1085.         printf("\t0x%04x", s);
  1086.         if (++t == 256)
  1087.             break;
  1088.         printf(",");
  1089.         }
  1090.     printf("};\n");
  1091. }
  1092. #endif
  1093.  
  1094. unsigned short crctab[256] = {
  1095.     0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241,
  1096.     0xc601, 0x06c0, 0x0780, 0xc741, 0x0500, 0xc5c1, 0xc481, 0x0440,
  1097.     0xcc01, 0x0cc0, 0x0d80, 0xcd41, 0x0f00, 0xcfc1, 0xce81, 0x0e40,
  1098.     0x0a00, 0xcac1, 0xcb81, 0x0b40, 0xc901, 0x09c0, 0x0880, 0xc841,
  1099.     0xd801, 0x18c0, 0x1980, 0xd941, 0x1b00, 0xdbc1, 0xda81, 0x1a40,
  1100.     0x1e00, 0xdec1, 0xdf81, 0x1f40, 0xdd01, 0x1dc0, 0x1c80, 0xdc41,
  1101.     0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, 0x1680, 0xd641,
  1102.     0xd201, 0x12c0, 0x1380, 0xd341, 0x1100, 0xd1c1, 0xd081, 0x1040,
  1103.     0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, 0xf281, 0x3240,
  1104.     0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441,
  1105.     0x3c00, 0xfcc1, 0xfd81, 0x3d40, 0xff01, 0x3fc0, 0x3e80, 0xfe41,
  1106.     0xfa01, 0x3ac0, 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840,
  1107.     0x2800, 0xe8c1, 0xe981, 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41,
  1108.     0xee01, 0x2ec0, 0x2f80, 0xef41, 0x2d00, 0xedc1, 0xec81, 0x2c40,
  1109.     0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, 0xe7c1, 0xe681, 0x2640,
  1110.     0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, 0x2080, 0xe041,
  1111.     0xa001, 0x60c0, 0x6180, 0xa141, 0x6300, 0xa3c1, 0xa281, 0x6240,
  1112.     0x6600, 0xa6c1, 0xa781, 0x6740, 0xa501, 0x65c0, 0x6480, 0xa441,
  1113.     0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41,
  1114.     0xaa01, 0x6ac0, 0x6b80, 0xab41, 0x6900, 0xa9c1, 0xa881, 0x6840,
  1115.     0x7800, 0xb8c1, 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41,
  1116.     0xbe01, 0x7ec0, 0x7f80, 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40,
  1117.     0xb401, 0x74c0, 0x7580, 0xb541, 0x7700, 0xb7c1, 0xb681, 0x7640,
  1118.     0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, 0x71c0, 0x7080, 0xb041,
  1119.     0x5000, 0x90c1, 0x9181, 0x5140, 0x9301, 0x53c0, 0x5280, 0x9241,
  1120.     0x9601, 0x56c0, 0x5780, 0x9741, 0x5500, 0x95c1, 0x9481, 0x5440,
  1121.     0x9c01, 0x5cc0, 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40,
  1122.     0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841,
  1123.     0x8801, 0x48c0, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x8a81, 0x4a40,
  1124.     0x4e00, 0x8ec1, 0x8f81, 0x4f40, 0x8d01, 0x4dc0, 0x4c80, 0x8c41,
  1125.     0x4400, 0x84c1, 0x8581, 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641,
  1126.     0x8201, 0x42c0, 0x4380, 0x8341, 0x4100, 0x81c1, 0x8081, 0x4040};
  1127.  
  1128.  
  1129. ^L
  1130. --MORE--(54%)
  1131. /*<
  1132.  * Function:fcrc16
  1133.  * Description:
  1134.  *  The algorithm comes from 
  1135.  *  "Byte-wise CRC Calculations" by Aram Perez,
  1136.  *  IEEE Micro June 1983 pp.40-50
  1137.  *
  1138.  * Returns:
  1139.  *  VOID
  1140.  * 
  1141. >*/
  1142.     
  1143. PUBLIC USHORT 
  1144. fcrc16 (i_fp, prev_crc, p_fsize)
  1145. FILE * i_fp;
  1146. USHORT prev_crc;
  1147. LONG * p_fsize;
  1148. {
  1149.     USHORT crc, x;
  1150.     INT c;
  1151.     LONG  fsize;
  1152.  
  1153.     crc = prev_crc;
  1154.     fsize = 0L;
  1155.     while ((c=getc(i_fp)) != EOF) {
  1156.         /* these are really the same.
  1157.          * crc = crctab[(crc^c)&0xff] ^ crc>>8;
  1158.          */
  1159.         x = (c^crc) & 0xFF;
  1160.         crc >>= 8;
  1161.         crc ^= crctab[x];
  1162.         ++fsize;
  1163.     }
  1164.         rewind(i_fp);           /* I don't like side effects */
  1165.     *p_fsize = fsize;
  1166.     return (crc);
  1167. }
  1168. !Funky!Stuff!
  1169. echo x - hxd.c
  1170. cat >hxd.c <<'!Funky!Stuff!'
  1171. /*+
  1172.  * File: hxd
  1173.  * Description:
  1174.  *  hxd, Hexadecimal dump is similar unix's "od -x"
  1175.  *  Displays the contents of a file in hexadecimal.
  1176.  *  If a byte is printable, it is also printed.
  1177.  *  format of output is :
  1178.  *  dec_add:hex_add word word word word word word word word  string  
  1179.  *  where:
  1180.  *      dec_add == Start address for that line in decimal. 
  1181.  *      hex_add == Start address for that line in hex. 
  1182.  *      word == Representation of two bytes in hex. Two characters
  1183.  *              for each byte. First two characters in "word" represent
  1184.  *              the byte that was read sooner.
  1185.  *      string == If the character is printable, it is printed.
  1186.  *                Otherwise a '.' is printed. '.'is printed as '.'.
  1187.  *  For each in put file name of the file is first emited.
  1188.  *      file: <i_file>
  1189.  *  last line for each input file is length of the file in 
  1190.  *      "dec_add:hex_add" format.
  1191.  *
  1192.  * Usages:
  1193.  *  hxd [-o] <o_file> <i_files>
  1194.  *
  1195.  *
  1196.  *  Author: Mohsen Banan.
  1197.  *
  1198.  *  This program is public domain software, no warranty intended or
  1199.  *  implied.
  1200.  *  General permission to copy or modify, but not for profit,  is
  1201.  *  hereby  granted.
  1202.  *
  1203.  *
  1204.  * Functions:
  1205.  *
  1206.  *
  1207.  * Audit Trail:  $Log:  hxd.c,v $
  1208.  * Revision 1.1  85/08/28  08:38:36  mohsen
  1209.  * original posting to the net
  1210.  * 
  1211.  * 
  1212.  *
  1213. -*/
  1214.  
  1215. #ifdef RCS_VER
  1216. static char *rcs = "$Header: hxd.c,v 1.1 85/08/28 08:38:36 mohsen Exp $";
  1217. #endif
  1218.  
  1219. /* #includes */
  1220. #include "mbstd.h"
  1221. #include <stdio.h>
  1222. #include <ctype.h>
  1223. #include <fcntl.h>
  1224. #ifdef unix
  1225. #include "msc3.h"
  1226. #endif
  1227.  
  1228. /* #defines */
  1229.  
  1230. /* external variables */
  1231.  
  1232. /* referenced external function declarations */
  1233.  
  1234. /* internal function declarations */
  1235. PUBLIC VOID hxd();
  1236. PUBLIC VOID hxdump();
  1237. PUBLIC VOID cant_open();
  1238. PUBLIC VOID printisc();
  1239. STATIC VOID usage();
  1240.  
  1241. /* global variables */
  1242.  
  1243. /* static variables */
  1244. STATIC CHAR * prog_name;
  1245.  
  1246. INT
  1247. main (argc, argv)
  1248. INT argc;
  1249. CHAR * argv[];
  1250. {
  1251.     hxd(argc, argv);
  1252. }
  1253.     
  1254. ^L
  1255. --MORE--(60%)
  1256. /*<
  1257.  * Function:hxd
  1258.  * Description:
  1259.  *  Parses the command line and calls hxdump.
  1260.  *  
  1261.  * Returns:
  1262.  *  VOID
  1263.  * 
  1264. >*/
  1265. PUBLIC VOID 
  1266. hxd (argc,argv)
  1267. INT argc;
  1268. CHAR * argv[];
  1269. {
  1270.     FILE * i_fp;
  1271.     FILE * o_fp;
  1272.     INT i;
  1273.  
  1274.     prog_name = argv[0];
  1275.     i_fp = stdin;
  1276.     o_fp = stdout;
  1277.     for (i=1; i<argc; ++i) {
  1278.         if (*argv[i] == '-') {
  1279.             /* To handle concatenated switches */
  1280.             INT j;
  1281.             j=i;
  1282.             while (*(++argv[j])) {
  1283.                 switch (*argv[j]) {
  1284.                 case 'o':
  1285.                 case 'O':
  1286.                     if ( !(o_fp = fopen(argv[++i], "w")) ) {
  1287.                         cant_open(prog_name, argv[i]);
  1288.                         exit(1);
  1289.                     }
  1290.                     break;
  1291.                 default:
  1292.                     usage();
  1293.                     exit(1);
  1294.                 } /* switch (*argv[j]) */
  1295.             } /* while (*(++argv[j])) */
  1296.         } /* if '-' */
  1297.         else {
  1298.             if (!(i_fp = fopen (argv[i], "r"))) {
  1299.                 cant_open (prog_name,  argv[i]);
  1300.                 exit (1);
  1301.             } 
  1302.             fprintf (o_fp, "file:   %s", argv[i]);
  1303.             setmode (fileno(i_fp), O_BINARY);
  1304.             setmode (fileno(o_fp), O_TEXT);
  1305.             hxdump (i_fp, o_fp);
  1306.             fclose (i_fp);
  1307.         }
  1308.     } /* for i<argc */
  1309.     fclose (o_fp);
  1310.     exit (0);
  1311. }
  1312.  
  1313. ^L
  1314. --MORE--(62%)
  1315. /*<
  1316.  * Function:HX_DUMP
  1317.  * Description:
  1318.  *
  1319.  * Arguments:
  1320.  *
  1321.  * Returns:
  1322.  *
  1323.  * Side Effects:
  1324.  *
  1325.  * Calls:
  1326.  * 
  1327. >*/
  1328. PUBLIC VOID
  1329. hxdump (i_fp, o_fp)
  1330. FILE * i_fp;
  1331. FILE * o_fp;
  1332. {
  1333. #define BYTESPERLINE 16
  1334.     LONG i = 0L;
  1335.     INT c;
  1336.     INT chars[BYTESPERLINE];
  1337.     INT j=0;
  1338.     INT k;
  1339.  
  1340.     while ((c = getc (i_fp)) != EOF) {
  1341.         if (! (i % BYTESPERLINE)) {
  1342.             if (i) {
  1343.                 j=0;
  1344.                 fprintf (o_fp, "  ");
  1345.                 printisc (o_fp,chars, BYTESPERLINE);
  1346.             }
  1347.                 
  1348.             fprintf (o_fp, "\n%07ld:%07lx", i,i );
  1349.         }
  1350.         if (!(i++ & 1)) {
  1351.             putc (' ', o_fp);
  1352.         }
  1353.         fprintf (o_fp, "%02x", c);
  1354.         chars[j++] = c;
  1355.     }
  1356.     if (k = (i % BYTESPERLINE)) {
  1357.         INT jj;
  1358.         k = BYTESPERLINE - k;
  1359.         for (jj=0; jj < (5*k/2)  ;++jj) {
  1360.             putc(' ', o_fp);
  1361.         }
  1362.     }
  1363.     fprintf (o_fp, "  ");
  1364.     printisc (o_fp, chars, BYTESPERLINE);
  1365.     fprintf (o_fp, "\n%07ld:%07lx\n", i,i);
  1366. }
  1367.  
  1368. PUBLIC VOID
  1369. cant_open (prog_name,filename)
  1370. CHAR * prog_name;
  1371. CHAR * filename;
  1372. {
  1373.     fprintf (stderr, "%s :can not open %s \n", prog_name, filename);
  1374.  
  1375. STATIC VOID
  1376. usage ()
  1377. {
  1378.     fprintf (stderr, "Usage: %s [-o] <o_file> <i_file> \n", prog_name);
  1379.      
  1380. }
  1381.  
  1382.  
  1383. PUBLIC VOID
  1384. printisc (o_fp, chars, length)
  1385. FILE * o_fp;
  1386. INT chars[];
  1387. INT length;
  1388. {
  1389.     INT i;
  1390.  
  1391.     for (i=0; i<length; ++i) {
  1392.         if (isprint (chars[i])) {
  1393.             putc (chars[i], o_fp);
  1394.         } else {
  1395.             putc ('.', o_fp);
  1396.         }
  1397.     }
  1398. }
  1399. !Funky!Stuff!
  1400. echo x - sarch.c
  1401. cat >sarch.c <<'!Funky!Stuff!'
  1402. /*+
  1403.  * File: SARCH
  1404.  * Description:
  1405.  *      This is a simple archive utility program.
  1406.  *      Sarch tries to only rely on the C stdio library functions.
  1407.  *      When transferring multiple files between two machines that only have a
  1408.  *      single file transfer utility, sarch becomes handy. Multiple files
  1409.  *      are converted to a sinle file on one end, transfered to the other 
  1410.  *      machine and extracted to the original files at the destination.
  1411.  *      System dependent features are very few, keeping it simple
  1412.  *      and portable. Efficiency is sacrificed for portability.
  1413.  *              CRCs are computed when updateing and when extracting.
  1414.  *  
  1415.  * Usage:
  1416.  *  sarch -{m,u,x,a,t} archname file1 .. filen
  1417.  *      -m      Print file names within the archive.
  1418.  *      -u      Add or update files to the archive.
  1419.  *      -x      Extract files from archive.
  1420.  *      -a      Extract all files from the rachive.
  1421.  *      -t      PCDOS related. When extracting, test mode is set.
  1422.  *
  1423.  *
  1424.  *  Author: Mohsen Banan.
  1425.  *
  1426.  *  This program is public domain software, no warranty intended or
  1427.  *  implied.
  1428.  *  General permission to copy or modify, but not for profit,  is
  1429.  *  hereby  granted.
  1430.  *
  1431.  *
  1432.  * Functions:
  1433.  *
  1434.  *  Sarch relies on the archive manipulating functions:
  1435.  *      ar_open(), ar_close()
  1436.  *      ar_get(), ar_put(), ar_seek().
  1437.  *      ar_get, gets (extracts) a file from the archive.
  1438.  *      ar_put, puts (adds) a file to the archive.
  1439.  *
  1440.  *
  1441.  * Audit Trail:  $Log:  sarch.c,v $
  1442.  * Revision 1.1  85/08/28  08:38:52  mohsen
  1443.  * original posting to the net
  1444.  * 
  1445.  * Revision 1.1  85/08/13  17:30:27  mohsen
  1446.  * Initial revision
  1447.  * 
  1448.  * Revision 1.2  85/04/25  10:27:22  mohsen
  1449.  * In this version sarch was working fine with the -a and -u options.
  1450.  * 
  1451.  * Revision 1.1  85/04/19  16:24:43  mohsen
  1452.  * Initial revision
  1453.  * 
  1454.  *
  1455. -*/
  1456.  
  1457. #ifdef RCS_VER
  1458. static char *rcs = "$Header: sarch.c,v 1.1 85/08/28 08:38:52 mohsen Exp $";
  1459. #endif
  1460.  
  1461. /* #includes */
  1462. #include "mbstd.h"
  1463. #include <stdio.h>
  1464. #include <fcntl.h>
  1465. #ifdef unix
  1466. #include "msc3.h"
  1467. #endif
  1468.  
  1469. /* #defines */
  1470. #define AR_BSTR     "<archive>"
  1471. #define AR_ESTR     "<archive>"
  1472.  
  1473. /*
  1474.  * All fileds of ARCH_HDR are strings (0 terminated),
  1475.  * All fields are left justified.
  1476.  */
  1477. typedef struct {
  1478.     CHAR ar_bstr[16];       /* begining archive string */
  1479.     CHAR fname[16];
  1480.     CHAR fsize[8];
  1481.     CHAR fcrc[8];
  1482.     CHAR ar_estr[16];       /* end archive string */
  1483. } ARCH_HDR;
  1484.  
  1485. /* external variables */
  1486.  
  1487. /* referenced external function declarations */
  1488. EXTERN USHORT fcrc16();
  1489.  
  1490. /* internal function declarations */
  1491. PUBLIC VOID sarch();
  1492. PUBLIC FILE * ar_open();
  1493. PUBLIC INT ar_close();
  1494. PUBLIC SUCC_FAIL ar_put();
  1495. PUBLIC SUCC_FAIL ar_get();
  1496. PUBLIC SUCC_FAIL ar_seek();
  1497. LOCAL VOID wr_hdr();
  1498. LOCAL SUCC_FAIL rd_hdr();
  1499. LOCAL VOID fld2str();
  1500. PUBLIC VOID cpf();
  1501. PUBLIC VOID cant_open();
  1502. STATIC VOID usage();
  1503.  
  1504. /* global variables */
  1505.  
  1506. /* static variables */
  1507. STATIC CHAR * prog_name;
  1508. STATIC ARCH_HDR gw_hdr;         /* generic write archive header */
  1509. STATIC ARCH_HDR gr_hdr;         /* generic read archive header */
  1510. STATIC BOOL txt_mode_flag;
  1511.  
  1512. INT
  1513. main (argc, argv)
  1514. INT argc;
  1515. CHAR * argv[];
  1516. {
  1517.     sarch(argc, argv);
  1518. }
  1519.     
  1520. ^L
  1521. --MORE--(72%)
  1522. /*<
  1523.  * Function:SARCH
  1524.  * Description:
  1525.  *  Parses the command line and relies on archive manipulating functions to do
  1526.  *  what it should do.
  1527.  *
  1528.  * Returns:
  1529.  *  VOID
  1530.  * 
  1531. >*/
  1532. PUBLIC VOID 
  1533. sarch (argc,argv)
  1534. INT argc;
  1535. CHAR * argv[];
  1536. {
  1537.     FILE * ar_fp;
  1538.  
  1539.     BOOL    add_flag;
  1540.     BOOL    xt_flag;
  1541.     BOOL    xt_all_flag;
  1542.  
  1543.     INT i;
  1544.  
  1545.     add_flag = xt_flag = xt_all_flag = txt_mode_flag = FALSE;
  1546.     ar_fp = stdout;
  1547.     prog_name = argv[0];
  1548.  
  1549.     sprintf (gw_hdr.ar_bstr, "%-15s", AR_BSTR);
  1550.     sprintf (gw_hdr.ar_estr, "%-15s", AR_ESTR);
  1551.  
  1552.     for (i=1; i<argc; ++i) {
  1553.         if (*argv[i] == '-') {
  1554.             /* To handle concatenated switches */
  1555.             INT j;
  1556.             j=i;
  1557.             while (*(++argv[j])) {
  1558.                 switch (*argv[j]) {
  1559.                 case 'u':
  1560.                 case 'U':
  1561.                     /*
  1562.                      * add or update a file to the archive
  1563.                      */
  1564.                     if (!(ar_fp = ar_open (argv[++i], "w"))) {
  1565.                         cant_open(prog_name, argv[i]);
  1566.                         exit (1);
  1567.                     }
  1568.                     add_flag = TRUE;
  1569.                     break;
  1570.                 case 'x':
  1571.                 case 'X':
  1572.                     /*
  1573.                      * Extract a file from the archive.
  1574.                      */
  1575.                     if (!(ar_fp = ar_open (argv[++i], "r"))) {
  1576.                         cant_open(prog_name,argv[i]);
  1577.                         exit(1);
  1578.                     }
  1579.                     xt_flag = TRUE;
  1580.                     break;
  1581.                 case 'a':
  1582.                 case 'A':
  1583.                     /*
  1584.                      * Extract all files with in this archive
  1585.                      */
  1586.                     if (!(ar_fp = ar_open (argv[i+1], "r"))) {
  1587.                         cant_open(prog_name,argv[i]);
  1588.                         exit(1);
  1589.                     }
  1590.                     xt_all_flag = TRUE;
  1591.                     break;
  1592.                 case 't':
  1593.                 case 'T':
  1594.                     txt_mode_flag = TRUE;
  1595.                     break;
  1596.                 default:
  1597.                     usage();
  1598.                     exit(1);
  1599.                 } /* switch (*argv[j]) */
  1600.             } /* while (*(++argv[j])) */
  1601.         } /* if '-' */
  1602.         else if (ar_fp == stdout) {
  1603.             /* 
  1604.              * This is equivalent to "-u" option, ar_fp is stdout.
  1605.              */
  1606.              add_flag = TRUE;
  1607.         }
  1608.         else {
  1609.             /*
  1610.              * the rest of command line arguments are assumed to be file names.
  1611.              */
  1612.             if (add_flag) {
  1613.                 ar_put (ar_fp, &gw_hdr,argv[i]);
  1614.             }
  1615.             else if (xt_flag) {
  1616.                 ar_seek (ar_fp, &gr_hdr, argv[i]);
  1617.                 ar_get (ar_fp,&gr_hdr);
  1618.             }
  1619.             else if (xt_all_flag) {
  1620.                 while ( ar_seek (ar_fp, &gr_hdr,(CHAR *) NULL) == SUCCESS ) {
  1621.                     ar_get (ar_fp, &gr_hdr);
  1622.                 }
  1623.             }
  1624.             else {
  1625.                 /*
  1626.                 OOPS();
  1627.                 */
  1628.             }
  1629.         }
  1630.     } /* for i<argc */
  1631.     ar_close (ar_fp);
  1632.     exit (0);
  1633. }
  1634.  
  1635. ^L
  1636. --MORE--(79%)
  1637. /*<
  1638.  * Function:ar_open
  1639.  * Description:
  1640.  *  Opens an archive directory.
  1641.  *
  1642.  * Returns:
  1643.  *  Same as fopen.
  1644.  *
  1645.  * 
  1646. >*/
  1647. PUBLIC FILE *
  1648. ar_open(path, type)
  1649. CHAR * path;
  1650. CHAR * type;
  1651. {
  1652.     FILE * fp;
  1653.     if ( fp=fopen(path,type) ) {
  1654.         setmode (fileno(fp), O_BINARY);
  1655.     }
  1656.     return (fp);
  1657. }
  1658.  
  1659.  
  1660.  
  1661. /*<
  1662.  * Function:ar_close
  1663.  * Description:
  1664.  *  Closes an archive file
  1665.  *
  1666.  * Returns:
  1667.  *  same as fclose.
  1668.  * 
  1669. >*/
  1670. PUBLIC INT
  1671. ar_close(ar_fp)
  1672. FILE * ar_fp;
  1673. {
  1674.     return (fclose(ar_fp));
  1675. }
  1676.  
  1677.  
  1678. ^L
  1679. --MORE--(80%)
  1680. /*<
  1681.  * Function: ar_put
  1682.  * Description:
  1683.  *  Puts the contents of the file specified in "path" into the archive.
  1684.  *  Archive header is written prior to copying the file.
  1685.  *
  1686.  * Returns:
  1687.  *  SUCCESS:    
  1688.  *      No problems.
  1689.  *  FAIL:
  1690.  *      Couldn't open the file that it is supposed to put it in.
  1691.  * 
  1692. >*/
  1693. PUBLIC SUCC_FAIL
  1694. ar_put(ar_fp, p_ar_hdr, path)
  1695. FILE * ar_fp;
  1696. ARCH_HDR * p_ar_hdr;
  1697. CHAR * path;
  1698. {
  1699.     FILE * fp;
  1700.     SUCC_FAIL retval;
  1701.     LONG fsize;
  1702.     USHORT crc;
  1703.  
  1704.     retval = SUCCESS;
  1705.     if (!(fp = fopen(path, "r"))) {
  1706.         cant_open (prog_name, path);
  1707.         retval = FAIL;
  1708.     } else {
  1709.         setmode (fileno(fp), O_BINARY);
  1710.         crc = fcrc16(fp, (USHORT)0, &fsize);
  1711.         rewind(fp);
  1712.         sprintf (p_ar_hdr->fsize, "%-7ld", fsize);
  1713.         sprintf (p_ar_hdr->fcrc, "%-7x", (int)crc);
  1714.         sprintf (p_ar_hdr->fname, "%-15s", path);
  1715.         wr_hdr(ar_fp, p_ar_hdr);
  1716.         cpf (fp, ar_fp, fsize);
  1717.         fclose(fp);
  1718.     }
  1719.     return (retval);
  1720. }
  1721.  
  1722. ^L
  1723. --MORE--(82%)
  1724. /*<
  1725.  * Function:ar_get
  1726.  * Description:
  1727.  *  Gets (extracts) the contents of a file from the archive.
  1728.  *  and stores it in the file specified in the archive header.
  1729.  *  ar_get is to be invoked after the execution of ar_seek.
  1730.  *
  1731.  * Returns:
  1732.  *  SUCCESS:
  1733.  *      Every thing went fine.
  1734.  *  FAIL:
  1735.  *      Couldn't open the file.
  1736.  *
  1737.  * 
  1738. >*/
  1739. PUBLIC SUCC_FAIL
  1740. ar_get(ar_fp, p_ar_hdr)
  1741. FILE  * ar_fp;
  1742. ARCH_HDR * p_ar_hdr;
  1743. {
  1744.     FILE * fp;
  1745.     SUCC_FAIL retval;
  1746.     LONG fsize;
  1747.     LONG nfsize;
  1748.     USHORT crc;
  1749.     USHORT ncrc;
  1750.     UINT   int_crc;
  1751.  
  1752.     retval = SUCCESS;
  1753.  
  1754.     if (!(fp = fopen(p_ar_hdr->fname, "w+"))) {
  1755.         cant_open (prog_name, p_ar_hdr->fname);
  1756.         retval = FAIL;
  1757.     } else {
  1758.                 setmode(fileno(fp), O_BINARY);
  1759.         sscanf (p_ar_hdr->fsize, "%ld", &fsize);
  1760.         cpf((FILE *)ar_fp, fp, fsize);
  1761.         rewind(fp);
  1762.         ncrc = fcrc16(fp, (USHORT)0, &nfsize);
  1763.         sscanf (p_ar_hdr->fcrc, "%x", &int_crc);
  1764.         crc = int_crc;
  1765.         if ( (crc != ncrc) || (fsize != nfsize) ) {
  1766.             retval = FAIL;
  1767.             fprintf(stderr, "%s: Problem extacting %s size=%ld, crc=%x\n",
  1768.                     prog_name, p_ar_hdr->fname, fsize, (int)crc);
  1769.             fprintf(stderr, "%s: Problem extacting %s nsize=%ld, ncrc=%x\n",
  1770.                     prog_name, p_ar_hdr->fname, nfsize, (int)ncrc);
  1771.         }
  1772.         fclose(fp);
  1773.     }
  1774.     return (retval);
  1775. }
  1776.  
  1777. ^L
  1778. --MORE--(85%)
  1779. /*<
  1780.  * Function: ar_seek
  1781.  * Description:
  1782.  *  If path is NULL, the current archive header is read into
  1783.  *  p_ar_hdr.
  1784.  *  Otherwise, the archive is searched for the specified file
  1785.  *  name addressed by path.
  1786.  *
  1787.  * Returns:
  1788.  *  SUCCESS if found.
  1789.  *  FAIL    if not found, or problem.
  1790.  *
  1791.  * 
  1792. >*/
  1793. LOCAL SUCC_FAIL
  1794. ar_seek(ar_fp, p_ar_hdr, path) 
  1795. FILE * ar_fp;
  1796. ARCH_HDR * p_ar_hdr;
  1797. CHAR * path;
  1798. {
  1799.     SUCC_FAIL retval;
  1800.  
  1801.     retval = SUCCESS;
  1802.     if (!path ) {
  1803.         /* then get it any way */
  1804.         retval = rd_hdr(ar_fp, p_ar_hdr);
  1805.     } else {
  1806.         
  1807.     }
  1808.     return (retval);
  1809. }
  1810.  
  1811. ^L
  1812. --MORE--(86%)
  1813. /*<
  1814.  * Function:wr_hdr
  1815.  * Description:
  1816.  *  Copy the contents of ARCH_HDR to the archive header.
  1817.  *  See rd_hdr for the file archive header picture.
  1818.  *
  1819.  * Returns:
  1820.  *  VOID
  1821.  * 
  1822. >*/
  1823. LOCAL VOID
  1824. wr_hdr (ar_fp, p_ar_hdr)
  1825. FILE * ar_fp;
  1826. ARCH_HDR * p_ar_hdr;
  1827. {
  1828.     fprintf (ar_fp , "%-15s", p_ar_hdr->ar_bstr);
  1829.     fprintf (ar_fp , "%-15s", p_ar_hdr->fname);
  1830.     fprintf (ar_fp , "%-7s", p_ar_hdr->fsize);
  1831.     fprintf (ar_fp , "%-7s", p_ar_hdr->fcrc);
  1832.     fprintf (ar_fp , "%-15s", p_ar_hdr->ar_estr);
  1833.     putc ('\n',ar_fp);
  1834. }
  1835.  
  1836. ^L
  1837. --MORE--(87%)
  1838. /*<
  1839.  * Function:rd_hdr
  1840.  * Description:
  1841.  *  Reads a header and fills up the ARCH_HDR.
  1842.  *
  1843. 0         1         2         3         4         5         6   
  1844. 0123456789012345678901234567890123456789012345678901234567890
  1845. 123456789012345678901234567890123456789012345678901234567890
  1846. b              b              b      b     b
  1847.     ar_bstr        fname        fsize  fcrc     ar_estr
  1848.  *
  1849.  * Returns:
  1850.  *  SUCCESS:
  1851.  *  FAIL:
  1852.  *      archive header is bad.
  1853.  *
  1854.  * 
  1855. >*/
  1856. LOCAL SUCC_FAIL
  1857. rd_hdr (ar_fp, p_ar_hdr)
  1858. FILE * ar_fp;
  1859. ARCH_HDR * p_ar_hdr;
  1860. {
  1861.     SUCC_FAIL   retval;
  1862.     CHAR    hdr_line[256];
  1863.     INT i;
  1864.  
  1865.     retval = SUCCESS;
  1866.     if (!fgets (hdr_line, 255,ar_fp)) {
  1867.         retval = FAIL;
  1868.     } else {
  1869.         fld2str (&hdr_line[0], p_ar_hdr->ar_bstr, 15);
  1870.  
  1871.         for (i=15; i<30; ++i) {
  1872.             if ( hdr_line[i] != ' ') {  
  1873.                 p_ar_hdr->fname[i-15] = hdr_line[i];
  1874.             } else {
  1875.                 break;
  1876.             }
  1877.         }
  1878.         p_ar_hdr->fname[i-15] = '\0';
  1879.                 
  1880.         fld2str (&hdr_line[30], p_ar_hdr->fsize, 7);
  1881.         fld2str (&hdr_line[37], p_ar_hdr->fcrc, 7);
  1882.         fld2str (&hdr_line[43], p_ar_hdr->ar_estr, 15);
  1883.     }
  1884.     return (retval);
  1885.  
  1886. }
  1887.  
  1888. LOCAL VOID
  1889. fld2str ( fld, str, size)
  1890. CHAR * fld;
  1891. CHAR * str;
  1892. INT size;
  1893. {
  1894.     INT i;
  1895.     for (i=0; i<size; ++i) {
  1896.         *str++ = *fld++;
  1897.     }
  1898.     *str = '\0';
  1899. }
  1900.  
  1901.     
  1902. ^L
  1903. --MORE--(90%)
  1904. /*<
  1905.  * Function:cpf
  1906.  * Description:
  1907.  *  Copy the first <fsize> bytes of <src_fp> to <dst_fp>
  1908.  *
  1909.  * Returns:
  1910.  *      VOID
  1911.  *
  1912.  * Side Effects:
  1913.  *      Both src_fp and dst_fp characters pointers are moved.
  1914.  *
  1915. >*/
  1916. LOCAL VOID
  1917. cpf (src_fp, dst_fp, fsize)
  1918. FILE * src_fp;
  1919. FILE * dst_fp;
  1920. LONG fsize;
  1921. {
  1922.     LONG i;
  1923.     for (i=0; i<fsize; ++i) {
  1924.         putc(getc(src_fp), dst_fp);
  1925.     }
  1926. }
  1927.  
  1928.  
  1929. PUBLIC VOID
  1930. cant_open (prog_name,filename)
  1931. CHAR * prog_name;
  1932. CHAR * filename;
  1933. {
  1934.     fprintf (stderr, "%s :can not open %s \n", prog_name, filename);
  1935.  
  1936. STATIC VOID
  1937. usage ()
  1938. {
  1939.     fprintf (stderr, "Usage: %s [-u] [-x] <filename> \n", prog_name);
  1940. }
  1941.  
  1942. !Funky!Stuff!
  1943. echo x - which.c
  1944. cat >which.c <<'!Funky!Stuff!'
  1945. /*+
  1946.  * File: which.c
  1947.  * Description:
  1948.  *  Tries to mimic Unix's which as closely as possible.
  1949.  *  
  1950.  * Usages:
  1951.  *  which <i_files>
  1952.  * 
  1953.  *
  1954.  *  Author: Mohsen Banan.
  1955.  *
  1956.  *  This program is public domain software, no warranty intended or
  1957.  *  implied.
  1958.  *  General permission to copy or modify, but not for profit,  is
  1959.  *  hereby  granted.
  1960.  *
  1961.  * Functions:
  1962.  *
  1963.  *
  1964.  * Audit Trail:  $Log:  which.c,v $
  1965.  * Revision 1.1  85/08/28  08:38:54  mohsen
  1966.  * original posting to the net
  1967.  * 
  1968.  * 
  1969.  *
  1970. -*/
  1971.  
  1972. #ifdef RCS_VER
  1973. static char *rcs = "$Header: which.c,v 1.1 85/08/28 08:38:54 mohsen Exp $";
  1974. #endif
  1975.  
  1976. /* #includes */
  1977. #include "mbstd.h"
  1978. #include <stdio.h>
  1979.  
  1980. /* #defines */
  1981. #ifdef BSD4_2
  1982. #define strchr index
  1983. #endif
  1984.  
  1985. /* external variables */
  1986.  
  1987. /* referenced external function declarations */
  1988. EXTERN char *getenv();
  1989. EXTERN char *strchr();
  1990. EXTERN char *strcat();
  1991.  
  1992. /* internal function declarations */
  1993. PUBLIC VOID which();
  1994. STATIC CHAR * get_head();
  1995. STATIC BOOL is_runable();
  1996. STATIC VOID usage();
  1997.  
  1998. /* global variables */
  1999.  
  2000. /* static variables */
  2001. STATIC CHAR * prog_name;
  2002.  
  2003. INT
  2004. main (argc, argv)
  2005. INT argc;
  2006. CHAR * argv[];
  2007. {
  2008.     which(argc, argv);
  2009. }
  2010.     
  2011. ^L
  2012. --MORE--(94%)
  2013. /*<
  2014.  * Function:which
  2015.  * Description:
  2016.  *
  2017.  * Returns:
  2018.  *  VOID
  2019.  * 
  2020. >*/
  2021. PUBLIC VOID 
  2022. which (argc,argv)
  2023. INT argc;
  2024. CHAR * argv[];
  2025. {
  2026.  
  2027.     INT i;
  2028.     CHAR * head, * nxt_head;        /* head concept is a-la Csh */
  2029.     BOOL end_of_path;
  2030.     BOOL not_in_path;
  2031.     STATIC CHAR file_buf[256];
  2032.     STATIC CHAR path_buf[512];
  2033.     CHAR * orig_path;
  2034.  
  2035.     prog_name = argv[0];
  2036.     if (argc < 2) {
  2037.         usage();
  2038.         exit(1);
  2039.     }
  2040.     if ((orig_path = getenv("PATH")) == NULL) {
  2041.         orig_path = ".";
  2042.     }
  2043.     for (i=1; i<argc; ++i) {
  2044.         end_of_path = FALSE;
  2045.         not_in_path = TRUE;
  2046.         strcpy (path_buf, orig_path);
  2047.         nxt_head = head = path_buf;
  2048.         while ( ! end_of_path ) {
  2049.             nxt_head = get_head (head);
  2050.             if ( nxt_head == NULL) {
  2051.                 end_of_path = TRUE;
  2052.             } else {
  2053.                 *nxt_head = '\0';
  2054.             }
  2055. #ifdef unix
  2056.             sprintf (file_buf, "%s/%s",(*head ? head:"."), argv[i]);
  2057. #endif
  2058. #ifdef MSDOS
  2059.             sprintf (file_buf, "%s\\%s",(*head ? head:"."), argv[i]);
  2060. #endif
  2061.             head = ++nxt_head;
  2062.             if ( is_runable(file_buf) ) {
  2063.                 printf ("%s\n", file_buf);
  2064.                 not_in_path = FALSE;
  2065.             }
  2066.         }
  2067.         if ( not_in_path ) {
  2068.             printf ("No %s in %s\n", argv[i], orig_path);
  2069.         }
  2070.     } /* for i<argc */
  2071.     exit (0);
  2072. }
  2073.  
  2074. STATIC VOID
  2075. usage ()
  2076. {
  2077.     fprintf (stderr, "Usage: %s cmd [cmd, ..]\n", prog_name);
  2078. }
  2079.  
  2080.  
  2081. STATIC CHAR * 
  2082. get_head (head)
  2083. CHAR * head;
  2084. {
  2085. #ifdef unix
  2086.     return (strchr( head, ':'));
  2087. #endif
  2088. #ifdef MSDOS
  2089.     return (strchr( head, ';'));
  2090. #endif
  2091. }
  2092.  
  2093. STATIC BOOL
  2094. is_runable (file_buf)
  2095. CHAR * file_buf;
  2096. {
  2097.     BOOL ret_val;
  2098.     CHAR * name, * root_name;   /* root is as defined by Csh */
  2099.  
  2100.     ret_val = FALSE;
  2101. #ifdef unix
  2102.     if ( access(file_buf, 1) == 0 ) {
  2103.         ret_val = TRUE;
  2104.     }
  2105. #endif
  2106. #ifdef MSDOS
  2107.     for (root_name=file_buf; *root_name; ++root_name);
  2108.     name = strcat(file_buf, ".com");
  2109.     if ( access(name, 0) == 0 ) {
  2110.         ret_val = TRUE;
  2111.     }
  2112.     else {
  2113.         *root_name = '\0';
  2114.         name = strcat(file_buf, ".exe");
  2115.         if ( access(name, 0) == 0 ) {
  2116.             ret_val = TRUE;
  2117.         }
  2118.         else {
  2119.             *root_name = '\0';
  2120.             name = strcat(file_buf, ".bat");
  2121.             if ( access(name, 0) == 0 ) {
  2122.                 ret_val = TRUE;
  2123.             }
  2124.         }
  2125.     }
  2126.     printf ("\n %s \n", name);
  2127. #endif
  2128.     return (ret_val);
  2129. }
  2130. !Funky!Stuff!
  2131.  
  2132.  
  2133. -- 
  2134.  
  2135.        !uw-beaver!tikal!mohsen                Mohsen Banan
  2136.        Teltone Corporation                    11811 93rd Ave. N.E. #304
  2137.        P.O. Box 657                           Kirkland, Wa 98033  USA
  2138.        Kirkland, Wa 98033  USA                tel: +1 (206) 821-8560
  2139.        tel: +1 (206) 827-9626               
  2140. (Mail) End of article 2703 (of 2730)--what next? [npq]